/*加载页面既调用方法*/
$(function () {
    $("#page").load("/back/page.html");
    findAll();
});
function findAll() {
    let data = {};
    data.username = $("#username").val();
    data.sex = $("#sex").find("option:selected").text();
    data.roomType = $("#roomType").val();
    data.channel = $("#channel").find("option:selected").text();
    data.phone = $("#phone").val();
    data.reservationTime = $("#reservationTime").val();
    data.checkInTime = $("#checkInTime").val();
    data.checkOutTime = $("#checkOutTime").val();
    data.pageSize = $.trim($("#pageSize").val());
    data.pageNum = $.trim($("#pageNum").val());
    data.token =$.cookie("token");
    let result = myAjax('/back/order/findAllOrder','get',data);
    showI(result.list);
    $("#pageCount").html(result.number);
}

function showI(data) {
    let html = "";//定一个一个空得html
    for (let i = 0; i < data.length; i++) {
        html += '  <tr>\n' +
            '        <td>' + data[i].id + '</td>\n' +
            '        <td>' + data[i].username + '</td>\n' +
            '        <td>' + (data[i].sex==null?'无':data[i].sex)+ '</td>\n' +
            '        <td>' + data[i].roomType + '</td>\n' +
            '        <td>' + (data[i].channel==null?'无':data[i].channel) + '</td>\n' +
            '        <td>' + data[i].phone + '</td>\n' +
            '        <td>' + (data[i].reservationTime==null?'无':data[i].reservationTime) + '</td>\n' +
            '        <td>' + data[i].checkInTime + '</td>\n' +
            '        <td>' + data[i].checkOutTime + '</td>\n' +
            '   <td><a  href="javascript:edit( ' + data[i].id + ')">编辑</a> <a  href="javascript:del( ' + data[i].id + ')">删除</a></td>\n' +
            '    </tr>';
    }
    $("#orderFindAll").html(html);//赋值
}

function edit(id) {
    localStorage.setItem("orderId", id);
    //sessionStorage.setItem("userId",id);   本地存储  两种方式都可以
    $('#right').load('/back/order/orderEdit.html');//页面跳转
}

function del(id) {
    let result = myAjax('/back/order/delete','get',{id:id,token:$.cookie("token")});
    if (result === 1) {
        $("#right").load('/back/order/orderManage.html');
    } else {
        alert("删除失败")
    }
}